package cn.yunyichina.provider.framework.dubbo.service;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import cn.yunyichina.provider.framework.data.SpringContextHandler;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.iface.service.IAuthorize;

import com.alibaba.fastjson.JSON;

public class AuthorizeService {

    static final String serviceName = "authorizeService";

    static IAuthorize authorizeService = null;

    static {
        authorizeService = (IAuthorize) SpringContextHandler.getBean(serviceName);
    }
    
    public static IAuthorize getAuthorizeClient(){
    	return authorizeService;
    }

    public static Response callUnderlineFromInternal(String method, String data) {
        return authorizeService.callUnderlineFromInternal("", method, data, (short) 0);
    }

    public static Response callUnderlineFromInternal(String sessionId, String method, String data) {
        return authorizeService.callUnderlineFromInternal(sessionId, method, data, (short) 0);
    }

    public static Response callHumpFromInternal(String sessionId, String method, String data) {
        return authorizeService.callHumpFromInternal(sessionId, method, data, (short) 0);
    }

    public static Response callHumpFromInternal(String method, String data) {
        return authorizeService.callHumpFromInternal("", method, data, (short) 0);
    }

    /**
     * 验证签名
     * 
     * @param httpParams
     * @return
     * @throws InvocationTargetException
     * @throws IllegalArgumentException
     * @throws IllegalAccessException
     */
    public static Response validate(Map<String, String> httpParams) {
        String jsonData = JSON.toJSONString(httpParams);
        String method = "yyt.authorize.signature.validate";
        return authorizeService.callUnderlineFromInternal("", method, jsonData, (short) 0);
    }
}
